<?php

namespace app\common\model;

use think\Model;

class Video extends Model
{
    protected $pk='video_id';
    protected $table='st_video';
    public function saveVideo($video){
        $check=$this->chheckData($video);
        if($check['valid']){
            $save=$this->save($video);
            if($save){
                return [
                    'valid'=>1,
                    'msg'=>'视频添加成功'
                ];
            }else{
                return [
                    'valid'=>0,
                    'msg'=>'视频添加失败'
                ];
            }
        }else{
            return $check;
        }


    }
    public function chheckData($video){
        $checkName=$this->where('video_name',$video['video_name'])->find();
        if ($checkName){

            return [
                'valid'=>0,
                'msg'=>'视频名称已存在'
            ];
        }
        $chechSort=$this->where('video_sort',$video['video_sort'])->find();
        if($chechSort){
            return [
                'valid'=>0,
                'msg'=>'视频排序已存在'
            ];
        }
        return [
            'valid'=>1,
            'msg'=>'ok'
        ];
    }
    public function searchName($vide_name){
        $video_list=$this->whereLike('video_name',"%".$vide_name."%")->select();
        foreach ($video_list as $k=>$v){
            $v['pro_name']=db('project')->where('pro_id',$v['video_pro_id'])->value('pro_name');
        }
        return $video_list;
    }
}
